import Vue from 'vue';
import axios from 'axios';
import {Dialog} from 'vant';    //注册弹框组件提示错误信息

axios.defaults.withCredentials = false;

//请求拦截
axios.interceptors.request.use(
	//成功
	function (config) {
		return config;
	},

	//失败
	function (error){
		return Promise.reject(error);
	},
);

//响应拦截
axios.interceptors.response.use(
	//成功
	function (response) {
		if(response.data.code != '200'){
			if(response.data.msg != '获取用户openId失败' && response.data.msg != '微信号未注册'){
				//弹框提示请求失败原因
				Dialog({
					message: response.data.msg,
				})
			}
		}

		return response;
	},

	//失败
	function (error) {
		//弹框提示错误信息
		Dialog({
			title: error.response.data.error,
			message: error.response.data.message,
		});

		return Promise.reject(error);
	}
);

export default axios;
